package com.khyr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.Vo.MedicinesVo;
import com.khyr.entity.StockMedicines;
import com.khyr.service.MedicinesService;
import com.khyr.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: MedicinesController
 * @author: Zyl
 * @date: 2025/3/12 21:52
 * @Version: 1.0
 * @description:
 */
@RestController
@RequestMapping("/erp/medicines")
public class MedicinesController {
    @Autowired
    private MedicinesService medicinesService;
    //分页查询药品信息
    @PostMapping("/listMedicinesForPage")

    public R<Page<StockMedicines>> findMedicines(@RequestBody MedicinesVo data){
        return medicinesService.findMedicines(data);

    }
    //新增药品信息
    @PostMapping("/addMedicines")
    public R addMedicines(@RequestBody MedicinesVo data){
        return medicinesService.addMedicines(data);
    }
    //修改药品信息回显
    @PostMapping("/getMedicinesById/{medicinesId}")
    public R getMedicinesById(@PathVariable Integer medicinesId){
        return medicinesService.getMedicinesById(medicinesId);
    }

    //修改药品信息
    @PutMapping("/updateMedicines")
    public R updateMedicines(@RequestBody MedicinesVo data){
        return medicinesService.updateMedicines(data);
    }
    //删除药品信息
    @DeleteMapping("/deleteMedicinesByIds/{medicinesIds}")
    public R deleteMedicinesByIds(@PathVariable List<Integer> medicinesIds){
        return medicinesService.deleteMedicinesByIds(medicinesIds);
    }
    //查询所有有效的药品信息
    @GetMapping("/selectAllMedicines")
    public R<List<StockMedicines>> selectAllMedicines(){
        return medicinesService.selectAllMedicines();
    }
    //调整库存
    @PostMapping("/updateMedicinesStorage/{medicinesId}/{medicinesStockNum}")
    public R adjustMedicinesStock(@PathVariable Integer medicinesId,@PathVariable Integer medicinesStockNum){
        return medicinesService.adjustMedicinesStock(medicinesId,medicinesStockNum);
    }
    //减库存
    @PostMapping("/reduce")
    public R reduce(String medicinesName,Integer medicinesStockNum) {
        return medicinesService.reduce(medicinesName,medicinesStockNum);
    }
    //加库存
    @PostMapping("/add")
    public R add(Long medicinesId,Integer medicinesStockNum) {
        return medicinesService.add(medicinesId,medicinesStockNum);
    }

}
